﻿@{
    Layout = "";
}

@model ActiveChatModel
@using Nop.Plugin.ActiveForever.ActiveChat.Models;
@using Nop.Web.Framework;
@using Nop.Web.Framework.UI;
@using Telerik.Web.Mvc.UI;

@using (Html.BeginForm())
{
    if (ViewData["Status"] != null)
    {
        <p style="color: #ff6a00">@ViewData["Status"].ToString()</p>
    }
    
    @Html.Telerik().TabStrip().Name("activechat-configure").Items(x =>
{
    x.Add().Text("Settings").Content(TabSettings().ToHtmlString()).Selected(true);
    x.Add().Text("Post Chat Email").Content(TabEmail().ToHtmlString());
    x.Add().Text("Import/Export").Content(TabImportExport().ToHtmlString());
})

    <input type="submit" name="save" class="t-button" value="@T("Admin.Common.Save")" />
   
}

@helper TabSettings()
{
    <table class="adminContent" style="width: 800px">
        <tr>
            <td class="adminTitle">Account Information:
            </td>
            <td class="adminData">
                <p>Full Version</p>
                <p>Account ID: <strong>Vintage Volks</strong></p>
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2">
                <hr />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">Offline Email Notifications Account
            </td>
            <td class="adminData">
                <select name="OfflineEmailAccountId" id="OfflineEmailAccountId">
                    @foreach (ConfiguredEmailAccount emailAccount in Model.ConfiguredEmailAccounts)
                    {
                        <option value="@emailAccount.AccountId">@emailAccount.AccountName</option>
                    }
                </select>
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2">
                <hr />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">Operator Welcome Message
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.OperatorWelcomeMessage)
                @Html.ValidationMessageFor(model => model.OperatorWelcomeMessage)
            </td>
        </tr>
        <tr class="adminSeparator">
            <td colspan="2">
                <hr />
            </td>
        </tr>
        <tr>
            <td class="adminTitle">Client Welcome Message (Online)
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.ClientWelcomeMessageOnline, new { style = "Width: 600px; Height: 100px;" })
                @Html.ValidationMessageFor(model => model.ClientWelcomeMessageOnline)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">Client Welcome Message (Offline)
            </td>
            <td class="adminData">
                @Html.TextAreaFor(model => model.ClientWelcomeMessageOffline, new { style = "Width: 600px; Height: 100px;" })
                @Html.ValidationMessageFor(model => model.ClientWelcomeMessageOffline)
            </td>
        </tr>
        <tr>
            <td class="adminTitle">Widget Image
            </td>
            <td class="adminData">
                @Html.EditorFor(model => model.WidgetImage)
                @Html.ValidationMessageFor(model => model.WidgetImage)
                <p>
                    Enter an the name of an image in your /Content/Images directory. Leave blank for default image.
                </p>
            </td>
        </tr>
    </table>
}

@helper TabEmail()
{ 
    var random = Nop.Core.CommonHelper.GenerateRandomInteger();
    
    <div>
        <p>
            @Html.EditorFor(m => m.EnablePostChatEmail)
            Enable Post Chat Email
            <hr />
        </p>
        <p>Create a custom email that will go out to the visitor once your chat has been complete. An email will only be sent if a valid email address was entered prior to chat.</p>
        <hr />
        <p>Usable tokens in the email body include:</p>
        <ul>
            <li>%TRANSCRIPT% - Inserts the chat transcript</li>
            <li>%VISITORNAME% - Inserts the visitor's name</li>
            <li>%OPERATORNAME% - Inserts the operator's name</li>
        </ul>
        <hr />
    </div>
    
    <div style="clear: both; margin: 10px 0">
        <label style="float: left; margin-right: 10px">Subject</label>
        @Html.TextBoxFor(m => m.PostChatEmailSubject, new { style = "width: 500px" })
    </div>
    
    @Html.Telerik().Editor().Name("PostChatEmail").HtmlAttributes(new { style = "height: 400px" }).Encode(false).Value(Model.PostChatEmail).Tools(tools => tools
    .Custom(settings => settings.HtmlAttributes(new { @class = "t-html", onclick = "viewRichHtmlEditorSource" + random + "(event)", title = "Edit HTML" })))

    <script type="text/javascript">
        var htmlSourcePopup;
    
        function viewRichHtmlEditorSource@(random)(e) {
            var editorSelector = 'PostChatEmail';
            e = $.Event(e);
            e.stopPropagation();
            e.preventDefault();
            var editor = $('#' + editorSelector.replace('.', '_')).data('tEditor');        
            var html = editor.value();

            if (!htmlSourcePopup) 
            {
                htmlSourcePopup =
                    $('<div class="html-view">' +
                            '<div class="textarea t-state-default"><textarea style="width: 100%; height: 300px;"></textarea></div>' +
                            '<div class="t-button-wrapper">' +
                                '<button id="htmlCancel" class="t-button" style="float: right;">@T("Admin.Common.Cancel")</button>' +
                                '<button id="htmlUpdate" class="t-button">@T("Admin.Common.Update")</button>' +
                            '</div>' +
                        '</div>')
                    .css('display', 'none')
                    .tWindow({
                        title: 'View Generated HTML',
                        modal: true,
                        resizable: false,
                        draggable: true,
                        width: 700,
                        onLoad: function () 
                        {
                            var $popup = $(this);
                            $popup.find('.textarea')
                                    .css('width', function () {
                                        return 700 - (this.offsetWidth - $(this).width());
                                    })
                                    .focus()
                                    .end()
                                    .find('#htmlCancel')
                                    .unbind('click')
                                    .click(function () {
                                        htmlSourcePopup.close();
                                    })
                                    .end()
                                    .find('#htmlUpdate')
                                    .unbind('click')
                                    .click(function () {
                                        var value = $popup.find('textarea').val();
                                        editor.value(value);
                                        htmlSourcePopup.close();
                                    });
                        },
                        onClose: function() {
                            editor.focus();
                        },
                        effects: $.telerik.fx.toggle.defaults()
                    })
                    .data('tWindow');
            }
        
            $(htmlSourcePopup.element).find('textarea').text(html);

            htmlSourcePopup.center().open();
        }
    </script>
}

@helper TabImportExport()
{
    <h3>Import</h3>
    <p>Click the 'Select import file' button below to load your exported ActiveChat data.</p>
    
    if (Model.ActiveChatDataExports.Count > 0)
    {
        <select id="SelectedImportFile" name="SelectedImportFile">
            @foreach (string file in Model.ActiveChatDataExports)
            {
                <option value="@file">@file</option>
            }
        </select>
        <input type="submit" name="import" class="t-button" value="Import Data" /><br />
    
    }
    else
    {
        <p><strong>No data exports found.</strong></p>   
    }
    
    <br /><hr /><br />
    <h3>Export</h3>
    <p>Click the 'Export data' button below to export all of your ActiveChat data.</p>
    <p>
        <input type="submit" name="export" class="t-button" value="Export Data" />
    </p>
    if (!string.IsNullOrEmpty(Model.StaticFileName))
    {
     
        <p>Last Export: @Model.StaticFileName</p>
                   
    }
}